#!/bin/bash



a=${install_dir}/${server_dir}/bin/redis-server
b=${install_dir}/${server_dir}/cluster/
c=${log_dir}/${server_dir}


start() {
    netstat -unltp | awk -F':' '{print $2}' | grep -w ${port} &> /dev/null
    if [ $? -ne 0 ];then
        $a $b/${port}/${port}.conf >> $c/redis_${port}.log &
    fi
}

stop() {
    netstat -unltp | awk -F':' '{print $2}' | grep -w ${port} &> /dev/null
    if [ $? -eq 0 ];then
        pid=`cat ${install_dir}/${server_dir}/cluster/${port}/redis_${port}.pid `
        kill -9 $pid &> /dev/null
    fi
}

status() {
    netstat -unltp | awk -F':' '{print $2}' | grep -w ${port} &> /dev/null
    [ $? -eq 0 ] && echo "redis port:${port} ok" || echo "redis port:${port} error"
}


if [ "$1" == "start" ];then
    start
elif [ "$1" == "stop" ];then
    stop
elif [ "$1" == "status" ];then
    status
else
    echo "start | stop | status"
fi
